loading...

طراحی اپلیکیشن در مشهد

بازدید : 28
چهارشنبه 21 خرداد 1404 زمان : 16:25


ساخت اینترنت سرور با استعمال از Node
Node.js یک ماژول http ارائه میدهد که می‌تواند برای ساخت یک خدمت گیرنده HTTP از طراحی اپلیکیشن در مشهد یک سرور استعمال شود.
ساختار تحت دست کم ساختار سرور HTTP میباشد که در پورت 8081 گوش می‌دهد.

یک فولدر js با اسم server.js ، تولید نمائید.

var http = require(\'http\');
var fs = require(\'fs\');
var url = require(\'url\');

// Create a server
http.createServer( function (request, response) {
// Parse the request containing file name
var pathname = url.parse(request.url).pathname;

// Print the name of the file for which request is made.
console.log("Request for " + pathname + " received.");

// Read the requested file content from file system
fs.readFile(pathname.substr(1), function (err, data) {
if (err) {
console.log(err);

// HTTP Status: 404 : NOT FOUND
// Content Type: text/plain
response.writeHead(404, {\'Content-Type\': \'text/html\'});
} else {
//Page found
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {\'Content-Type\': \'text/html\'});

// Write the content of the file to response body
response.write(data.toString());
}

// Send the response body
response.end();
});
}).listen(8081);

// Console will print the message
console.log(\'Server running at http://127.0.0.1:8081/\');
COPY
اکنون اذن دهید پوشه html تحت را با اسم index.htm در به عبارتی فهرستی که server.js را تولید کردید ساخت‌و‌ساز کنیم.

Hello World!


COPY
درحال حاضر اذن دهید server.js را اعمال کنیم تا فیض را ببینیم :

$ node server.js
COPY
خروجی را پذیرش فرمائید :

Server running at http://127.0.0.1:8081/


ساخت اینترنت سرور با استعمال از Node
Node.js یک ماژول http ارائه میدهد که می‌تواند برای ساخت یک خدمت گیرنده HTTP از طراحی اپلیکیشن در مشهد یک سرور استعمال شود.
ساختار تحت دست کم ساختار سرور HTTP میباشد که در پورت 8081 گوش می‌دهد.

یک فولدر js با اسم server.js ، تولید نمائید.

var http = require(\'http\');
var fs = require(\'fs\');
var url = require(\'url\');

// Create a server
http.createServer( function (request, response) {
// Parse the request containing file name
var pathname = url.parse(request.url).pathname;

// Print the name of the file for which request is made.
console.log("Request for " + pathname + " received.");

// Read the requested file content from file system
fs.readFile(pathname.substr(1), function (err, data) {
if (err) {
console.log(err);

// HTTP Status: 404 : NOT FOUND
// Content Type: text/plain
response.writeHead(404, {\'Content-Type\': \'text/html\'});
} else {
//Page found
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {\'Content-Type\': \'text/html\'});

// Write the content of the file to response body
response.write(data.toString());
}

// Send the response body
response.end();
});
}).listen(8081);

// Console will print the message
console.log(\'Server running at http://127.0.0.1:8081/\');
COPY
اکنون اذن دهید پوشه html تحت را با اسم index.htm در به عبارتی فهرستی که server.js را تولید کردید ساخت‌و‌ساز کنیم.

Hello World!


COPY
درحال حاضر اذن دهید server.js را اعمال کنیم تا فیض را ببینیم :

$ node server.js
COPY
خروجی را پذیرش فرمائید :

Server running at http://127.0.0.1:8081/

نظرات این مطلب

تعداد صفحات : 0

درباره ما
موضوعات
آمار سایت
  • کل مطالب : 394
  • کل نظرات : 0
  • افراد آنلاین : 1
  • تعداد اعضا : 0
  • بازدید امروز : 12
  • بازدید کننده امروز : 0
  • باردید دیروز : 69
  • بازدید کننده دیروز : 0
  • گوگل امروز : 0
  • گوگل دیروز : 0
  • بازدید هفته : 266
  • بازدید ماه : 1577
  • بازدید سال : 3931
  • بازدید کلی : 21247
  • <
    پیوندهای روزانه
    اطلاعات کاربری
    نام کاربری :
    رمز عبور :
  • فراموشی رمز عبور؟
  • خبر نامه


    معرفی وبلاگ به یک دوست


    ایمیل شما :

    ایمیل دوست شما :



    کدهای اختصاصی